package org.his.controller.quanxian;

import org.his.dao.MenuFotonDao;
import org.his.pojo.quanxuan.MenuFoton;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/menuforon")
public class MenuFotonController {

    @Autowired
    private MenuFotonDao menuFotonDao;


    @RequestMapping("/index")
    public String index() throws  Exception{
        return "quanxian/permission/index";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list() throws Exception{
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msp",null);
        map.put("data",menuFotonDao.getAll());
        return map;
    }
    @RequestMapping("/jibie")
    @ResponseBody
    public List<MenuFoton> getjibie() throws  Exception{
        return menuFotonDao.getjibie();
    }
    @RequestMapping("/isErJi")
    @ResponseBody
    public Map<String,Object> isErJi(Integer menuid) throws Exception{
        Map<String,Object> map = new HashMap<>();

        List<MenuFoton> menuFotonList = menuFotonDao.isErJI(menuid);

        if (menuFotonList!= null && menuFotonList.size()!= 0){
            map.put("code",1);
        }else if (menuFotonList.size()== 0){
            map.put("code",0);
        }
        map.put("data",menuFotonList);
        return map;
    }


    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> del(Integer menuid) throws Exception{
        Map<String,Object> map = new HashMap<>();
        menuFotonDao.delete(menuid);
        return map;
    }


    @RequestMapping("/menufotonfrom")
    public String menufoton() throws Exception{
        return "quanxian/permission/MenuForonFrom";
    }

    @RequestMapping("/menufotonfrom2")
    public String menufoton2() throws Exception{
        return "quanxian/permission/MenuForonFrom2";
    }

    @RequestMapping("/yiji")
    @ResponseBody
    public List<MenuFoton> yiji() throws Exception{
        return menuFotonDao.yiji();
    }

    @RequestMapping("/erji")
    @ResponseBody
    public List<MenuFoton> erji(Integer parentid) throws Exception{
        return menuFotonDao.erji(parentid);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(MenuFoton menuFoton) throws Exception{
        Map<String,Object> map = new HashMap<>();

        menuFotonDao.add(menuFoton);

        return map;
    }

    @RequestMapping(value = "rolePers",method = RequestMethod.GET)
    @ResponseBody
    public List<Integer> rolePers(Integer roleId) throws Exception{
        return menuFotonDao.getPByRoleId(roleId);
    }

    @RequestMapping(value = "getMenuFoton",method = RequestMethod.GET)
    @ResponseBody
    public MenuFoton getMenuFoton(Integer menuid) throws Exception{
        return menuFotonDao.get(menuid);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String , Object> updMenuFoton(MenuFoton menuFoton) throws Exception{
        Map<String,Object> map = new HashMap<>();

        menuFotonDao.update(menuFoton);

        return map;
    }


}
